﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace c_Windows
{
    public partial class Bar : Form
    {
        public HomeBegin MB1;
        public Bar(HomeBegin M1)
        {
            InitializeComponent();
            M1 = MB1;
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }


        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                textBox2.AppendText(DateTime.Now.ToString("HH:mm:ss ") + "进度条开始运行" + "\t\n");
                if (textBox1.Text == "")
                    return;
                progressBar1.Value = 0;
                progressBar1.Minimum = 0;
                progressBar1.Maximum = Convert.ToInt32(textBox1.Text);
                timer1.Enabled = true;
            }
            catch (ArgumentOutOfRangeException)
            {
                textBox2.AppendText(DateTime.Now.ToString("HH:mm:ss ") + "请修改 进度条长度 > 0 || 进度条长度 < 2147483647！" + "\t\n");
                timer1.Enabled = false;
                textBox2.AppendText(DateTime.Now.ToString("HH:mm:ss ") + "进度条停止运行" + "\t\n");
            }
            catch (OverflowException)
            {
                textBox2.AppendText(DateTime.Now.ToString("HH:mm:ss ") + "请修改 进度条长度 > 0 || 进度条长度 < 2147483647！" + "\t\n");
                timer1.Enabled = false;
                textBox2.AppendText(DateTime.Now.ToString("HH:mm:ss ") + "进度条停止运行" + "\t\n");
            }
            catch (FormatException)
            {
                textBox2.AppendText(DateTime.Now.ToString("HH:mm:ss ") + "请修改进度条长度没有符号（如：.、-、*、/、&、……、%、￥、#、@、!、[、]、《、》等等）" + "\t\n");
                timer1.Enabled = false;
                textBox2.AppendText(DateTime.Now.ToString("HH:mm:ss ") + "进度条停止运行" + "\t\n");
            }
        }


        private void button2_Click(object sender, EventArgs e)
        {
            if (timer1.Enabled == true)
            {
                textBox2.AppendText(DateTime.Now.ToString("HH:mm:ss ") + "进度条停止运行" + "\t\n");
                timer1.Enabled = false;
                button2.Text = "继续";
            }
            else
            {
                textBox2.AppendText(DateTime.Now.ToString("HH:mm:ss ") + "进度条开始运行" + "\t\n");
                timer1.Enabled = true;
                button2.Text = "暂停";
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            textBox2.AppendText(DateTime.Now.ToString("HH:mm:ss ") + "进度条停止运行" + "\t\n");
            timer1.Enabled = false;
            progressBar1.Value = 0;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                timer1.Interval = Convert.ToInt32(textBox3.Text);
                if (progressBar1.Value < progressBar1.Maximum)
                {
                    progressBar1.Value++;
                    textBox2.AppendText(DateTime.Now.ToString("HH:mm:ss ") + "进度条进行中 [ " + progressBar1.Value.ToString() + " / " + progressBar1.Maximum.ToString() + " ] " + "\t\n");
                }
                else
                {
                    textBox2.AppendText(DateTime.Now.ToString("HH:mm:ss ") + "进度条已完成" + "\t\n");
                    timer1.Enabled = false;
                }
            }
            catch (ArgumentOutOfRangeException)
            {
                textBox2.AppendText(DateTime.Now.ToString("HH:mm:ss ") + "请修改 时间间隔 > 0 || 时间间隔 < 2147483647！" + "\t\n");
                timer1.Enabled = false;
                textBox2.AppendText(DateTime.Now.ToString("HH:mm:ss ") + "进度条停止运行" + "\t\n");
            }
            catch (OverflowException)
            {
                textBox2.AppendText(DateTime.Now.ToString("HH:mm:ss ") + "请修改 时间间隔 > 0 || 时间间隔 < 2147483647！" + "\t\n");
                timer1.Enabled = false;
                textBox2.AppendText(DateTime.Now.ToString("HH:mm:ss ") + "进度条停止运行" + "\t\n");
            }
            catch (FormatException)
            {
                textBox2.AppendText(DateTime.Now.ToString("HH:mm:ss ") + "请修改时间间隔没有符号（如：.、-、*、/、&、……、%、￥、#、@、!、[、]、《、》等等）" + "\t\n");
                timer1.Enabled = false;
                textBox2.AppendText(DateTime.Now.ToString("HH:mm:ss ") + "进度条停止运行" + "\t\n");
            }
        }


    }
}
